package com.zxy.auth.findhouse.com.service.impl;

import com.zxy.auth.findhouse.com.config.JwtUtil;
import com.zxy.auth.findhouse.com.config.SmsUtil;
import com.zxy.common.utils.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.Random;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxy.common.utils.PageUtils;
import com.zxy.common.utils.Query;

import com.zxy.auth.findhouse.com.dao.AdminDao;
import com.zxy.auth.findhouse.com.entity.AdminEntity;
import com.zxy.auth.findhouse.com.service.AdminService;


@Service("adminService")
public class AdminServiceImpl extends ServiceImpl<AdminDao, AdminEntity> implements AdminService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<AdminEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        String key1 = (String) params.get("key1");
        String key2 = (String) params.get("key2");
        if (StringUtils.isNotEmpty(key)){
            wrapper.and(w->{
                w.like("name",key);
            });
        }
        if (StringUtils.isNotEmpty(key1)){
            wrapper.and(w->{
                w.gt("price",key1);
            });
        }
        if (StringUtils.isNotEmpty(key2)){
            wrapper.and(w->{
                w.lt("price",key2);
            });
        }

        IPage<AdminEntity> page = this.page(
                new Query<AdminEntity>().getPage(params),
                wrapper
        );
        return new PageUtils(page);
    }

    @Override
    public void sendSms(String phone) throws Exception {
        String code = "";
        Random random = new Random();
        for(int i = 0; i<4;i++){

            code+= random.nextInt(10);
        }
        System.out.println("本次生成的验证码为："+code);
        SmsUtil.show(phone,code);

    }




}